//package com.wffz.task;
//import com.wffz.comm.utils.DateUtils;
//import com.wffz.po.Patch;
//import com.wffz.service.PatchService;
//import com.wffz.service.TaskConfigService;
//import lombok.Data;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.PropertySource;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.SchedulingConfigurer;
//import org.springframework.scheduling.config.ScheduledTaskRegistrar;
//import org.springframework.scheduling.support.CronTrigger;
//import org.springframework.stereotype.Component;
//import javax.annotation.Resource;
//
///**
// * @author sunlei
// * @className ScheduleTask
// * @Description
// * @date 2023-02-12 10:32
// **/
//@Data
//@Slf4j
//@Component
//@PropertySource("classpath:/task-config.ini")
//@EnableScheduling
//public class ScheduleTask implements SchedulingConfigurer {
//    @Value("${printTime.cron}")
//    private String cron;
//    @Resource
//    private TaskConfigService taskConfigService;
//
//    @Resource
//    private PatchService patchService;
//
//    @Resource
//    private StringRedisTemplate stringRedisTemplate;
//
//    @Override
//    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
//        taskRegistrar.addTriggerTask(() -> process(),
//                triggerContext -> {
//                    if (cron.isEmpty()) {
//                        System.out.println("cron is null");
//                    }
//                    return new CronTrigger(cron).nextExecutionTime(triggerContext);
//                });
//    }
//
//    private void process() {
//        String v = stringRedisTemplate.opsForValue().get("task_business");
//        if(v.equals("0")){
////            log.info("业务定时任务未开启");
//            return;
//        }
//        log.info("每秒执行一次，执行时间 : " + DateUtils.getNowDate());
//        // 获取当天当前期
//        Patch patch = patchService.getCurrentPeriod();
//        // 如果没有数据  返回NULL
//        if (patch == null) {
//            return;
//        }
//        // 获取当前期码
//        String patchNum = patch.getPatchNum();
//        // 获取下期期码
//        String nextPatchNum = String.valueOf(Long.parseLong(patchNum) + 1);
//        // 下期期码对象
//        Patch nextPatch = patchService.getPatchByNum(nextPatchNum);
//        // 倒数数字
//        int countDown = patch.getCountDown();
//        if (countDown == 0) {
//            patch.setStatus("2");
//            nextPatch.setStatus("1");
//            patchService.updatePatch(nextPatch);
//        }
//        countDown--;
//        log.info("countDown : " + countDown);
//        patch.setCountDown(countDown);
//        patchService.updatePatch(patch);
//    }
//
//}
